<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head >
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%@ include file="/pub/head_latest.inc"%>
<%@ include file="/web/pub/head.inc"%>
<link href="${baseURL}/themes/plugin/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="${baseURL}/themes/plugin/bootstrap-dialog/css/bootstrap-dialog.css" rel="stylesheet" type="text/css" />
<link href="${baseURL}/themes/plugin/bootstrapTable/bootstrap-table.css" rel="stylesheet" type="text/css" />
<link href="${baseURL}/themes/blue/css/sys.css" rel="stylesheet" type="text/css" />
<script src="${baseURL}/js/jquerys/jquery-1.12.1.min.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/bootstrap-dialog/js/bootstrap-dialog.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/bootstrapTable/bootstrap-table.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/bootstrapTable/locale/bootstrap-table-zh-CN.min.js" type="text/javascript"></script>
<script src="${baseURL}/js/BT.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/ligerUI_latest/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/ligerUI_latest/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/ligerUI_latest/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
<script src="${baseURL}/themes/plugin/ligerUI_latest/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
<script src="${baseURL}/js/sdAppFrameworkAddressBook.js" type="text/javascript"></script>

	<script>
		function ev_new() {
			pageShowForm("${ROOT}/system/security/resource/editResource.do?parentResourceId=${parentResource.id}&resourceId=");
		}
		function ev_edit(id) {
			pageShowForm("${ROOT}/system/security/resource/editResource.do?parentResourceId=${parentResource.id}&resourceId="+id);
		}
		
		function ev_del(id) {
			var selectedRow = $('#maingrid').bootstrapTable('getSelections');
	     	if (!selectedRow || selectedRow.length <= 0) { alert("请选择要删除的记录"); return false;}
	     	if (selectedRow.length > 1) { alert("一次只能删除一条记录"); return false;}
	     	var mdata = {parentResourceId:"${parentResource.id}"};
	     	var arr = new Array();
	     	for(var index in selectedRow){
	     		arr[index] = selectedRow[index].id;
	     	}
	     	mdata.selectedrow=arr[0];
	     	BT.showConfirm('删除','确定删除所选的记录吗？',function(){
	    		 $.ajax({
						type: "post",
						url: "${ROOT}/system/security/resource/delResourceForJSON.do",
						dataType : "json",
						data: mdata,
						success: function(data){
							parent.FF_Reload();
							$("#maingrid").bootstrapTable('refresh');
							window.location="${ROOT}/system/security/resource/listResource.do?parentResourceId=${parentResource.id}";
						}
				 });
				});
	     	
		}
		function swapResource(currId,swapId,parentId){
			var url = "${ROOT}/system/security/resource/swapResource.do?currId="+currId+"&swapId="+swapId+"&parentId="+parentId;
			window.location = url;
		}
	</script>
	<style type="text/css">
	.bootstrap-dialog-message{text-align:center;}
.bootstrap-dialog-message>p{text-align:center;}
.bootstrap-dialog-message>h4{text-align:center;}
.bootstrap-dialog-footer-buttons{text-align:center;}
	</style>
</head>
<body class="FrameRightBg" style="background:#fff">
<div class="FrameRight" id="FrameRightContent">
		<!-- 这里定义了转发进入的TAB对应的菜单ID，也是TAB的属性ID值 -->
		<input type="hidden" name="menuId" id="menuId" value="${param.menuId}" />
		<div id="mainsearch" style="width: 100%; margin-left: 0px">
			<form id="formsearch" class="l-form" method="post">
			<input type="hidden" name="parentResourceId" id="parentResourceId" value="${parentResource.id }"/>
			</form>
		</div>
		<div class="common-option" style="margin-top: 5px">
			<div class="inner">
				<button id="add" type="button" class="btn btn-icon" onclick="ev_new()">
					<i class="l-icon l-icon-a fa fa-plus-square-o"></i>新增
				</button>
				<button id="delete" type="button" class="btn btn-icon" onclick="ev_del()">
					<i class="l-icon l-icon-a fa fa-minus-square-o"></i>删除
				</button>
			</div>
		</div>
		<!-- 表格列表 -->
		<div class="common-table">
			<table id="maingrid" style="margin-left: 0px; width: 100%"></table>
		</div>


	</div>
</body>
<script type="text/javascript">
var newData = [];
<c:if test="${not empty resourceList}">
newData = ${resourceList};
</c:if>

function initTable() {
		
		$('#maingrid').bootstrapTable({
	     	striped: true,                      //是否显示行间隔色
	        pageNumber:1,                       //初始化加载第一页，默认第一页
	     	pagination: true,
	     	sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
	     	pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
	        clickToSelect: true,                //是否启用点击选中行
	        uniqueId: "id",                 //每一行的唯一标识，一般为主键列
   			columns: [{
            	checkbox: true
        	},{
	            field: 'code',
	            title: '编号',
	            formatter: function (value, Rows, index) {
						return value;
	            }
	        },{
               field: 'name',
               title: '名称',
	               formatter: function (value, row, index) {
	                   return "<a style=\"color:#2684ce\" onclick=\"ev_edit(\'" + row.id + "\');return false;\" href=\"#\">" + value + "&nbsp;</a>";  
	               }
           },  {
               field: 'type',
               title: '类别',
               formatter: function (value, Rows, index) {
            	   return value;
               }
		   }, {
               field: 'resourceType',
               title: '资源类别',

               formatter: function (value, Rows, index) {
            	   if(Rows.resourceType == 0 || !Rows.resourceType){
            		   return '菜单';
            	   }
            	   return '按钮';
               }
		   },{
               field: 'url',
               title: 'URL',
               formatter: function (value, Rows, index) {
					return value;
               }
		   }, {
               field: 'priority',
               title: '排序',
               formatter: function (value, Rows, index) {
					return value;
               }
		   }]
		})
}



		$(function () {
			$("#maingrid").css("text-align","center");
			initTable();
			$("#maingrid").bootstrapTable('load', newData);
		}) 

 
</script>
</html>
